﻿#include "TurnController.h"

#include <boost/bind.hpp>
#include "../domain/models/Player.h"

using namespace Controllers;

TurnController::TurnController(AccusationController* accusation_controller, BoardController* board_controller, DeductionController* deduction_controller)
	: accusation_controller(accusation_controller), board_controller(board_controller), deduction_controller(deduction_controller)
{
	connectEvent<void ()>(accusation_controller->accusationCorrectEvent, boost::bind(&TurnController::onAccusationCorrect, this));
	connectEvent<void ()>(accusation_controller->accusationIncorrectEvent, boost::bind(&OnPlayerLose::operator(), &playerLoseEvent));
	connectEvent<void ()>(accusation_controller->accusationNotPerformedEvent, boost::bind(&TurnController::performMove, this));

	connectEvent<void ()>(board_controller->movePerformedEvent, boost::bind(&TurnController::performDeduction, this));
	connectEvent<void ()>(deduction_controller->deductionPerformedEvent, boost::bind(&TurnController::end, this));
}

TurnController::~TurnController()
{
	delete accusation_controller;
	delete board_controller;
	delete deduction_controller;
}

void TurnController::begin() 
{
	performAccusation();
}

void TurnController::performAccusation()
{
	accusation_controller->perform();
}

void TurnController::onAccusationCorrect()
{
	playerWinEvent();
}

void TurnController::performMove()
{
	board_controller->perform();
}

void TurnController::performDeduction()
{
	deduction_controller->perform();
}

void TurnController::end()
{
	turnEndEvent();
}

